<template>
	<view class="pages">
		<!-- 		<view class="pages_title">
			Welcome !
		</view> -->
		<view class="items">
			<view class="itemsTip">
				<span>*</span>
				<span>{{$t('ChangePassword.oldpass')}}</span>
			</view>
			<view class="sd">
				<u--input :placeholder="$t('ChangePassword.oldpasstps')" border="surround" v-model="FormData.old_password"
					:customStyle="{width:'650rpx',height:'49rpx'}" password clearable></u--input>
			</view>
		</view>
		<view class="items">
			<view class="itemsTip">
				<span>*</span>
				<span>{{$t('ChangePassword.newpass')}}</span>
			</view>
			<view class="sd">
				<u--input :placeholder="$t('ChangePassword.newpasstps')" border="surround" v-model="FormData.new_password"
					:customStyle="{width:'650rpx',height:'49rpx'}" password clearable></u--input>
			</view>
		</view>
		<view class="items">
			<view class="itemsTip">
				<span>*</span>
				<span>{{$t('ChangePassword.Confirmnewpassword')}}</span>

			</view>
			<view class="sd">
				<u--input :placeholder="$t('ChangePassword.Confirmnewpasswordtps')" border="surround" v-model="ConfirmPassword"
					:customStyle="{width:'650rpx',height:'49rpx'}" password clearable></u--input>
			</view>
		</view>
		<view class="items">
			<view class="itemsTip">
				<span>*</span>
				<span>{{$t('ChangePassword.Email')}}</span>

			</view>
			<view class="sd">
				<u--input :placeholder="$t('ChangePassword.Emailtps')" border="surround" v-model="email"
					:customStyle="{width:'650rpx',height:'49rpx'}" disabled="true" clearable></u--input>
			</view>
		</view>
		<view class="items">
			<view class="itemsTip">
				<span>*</span>
				<span>{{$t('ChangePassword.Verifycode')}}</span>

			</view>
			
			<view class="sd">
				<u--input :placeholder="$t('ChangePassword.Verifycodetps')" border="surround" v-model="FormData.code"
					:customStyle="{width:'650rpx',height:'49rpx'}" clearable></u--input>
				<u-button type="primary" :text="tips"
					:customStyle="{width:'250rpx',height:'75rpx',backgroundColor:'#273562',color:'#fff',fontWeight:'700',border:'none'}"
					@click="sendcode" :disabled="codedisabled"></u-button>
			</view>
		</view>

		<view class="g">
			<u-button type="primary" :text="$t('ChangePassword.Confirm')"
				:customStyle="{width:'320rpx',height:'80rpx',backgroundColor:'#273562',color:'#fff',margin:'30rpx 0 0rpx',fontWeight:'700',border:'none',borderRadius:'10rpx'}"
				@click="submit"></u-button>
				<u-button type="primary" :text="$t('ChangePassword.Resetcontent')"
					:customStyle="{width:'320rpx',height:'80rpx',backgroundColor:'#fff',color:'#666',margin:'30rpx 0 0rpx',fontWeight:'700',border:'none',borderRadius:'10rpx',border:'2rpx solid #273562'}"
					@click="Set"></u-button>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				newUrl:1,//0为新接口1为老接口
				FormData: {
					old_password: '',
					new_password: '',
					code: ''
				},
				ConfirmPassword: '',
				email: JSON.parse(uni.getStorageSync('user')).email,
				tips: `${this.$t('ChangePassword.tips')}`,
				codedisabled:false
			}
		},
		methods: {
			// 重置内容
			Set() {
				this.FormData = {}
				this.ConfirmPassword = ''
			},
			// 发送验证码
			sendcode() {
				this.codedisabled = true
				var num = 60;
				if (!this.email) {
					this.$ToastFail(this.$t('Emailisrequired'));
					return;
				}

				var that = this;
			const timer = setInterval(function() {
					if (num > 0) {
						num -= 1
						that.tips = `${num}` + that.$t('ChangePassword.tipsd')
					} else {
						num = 60
						clearInterval(timer)
						that.tips = that.$t('ChangePassword.tips')
						that.codedisabled = false
					}
				}, 1000);
				this.$get('/backend/login/sendEmailCode2',{
					email:this.email
				},this.newUrl)
				// 这里可以继续写其他代码
			},
	
			// 提交数据
			submit() {
				if (!this.FormData.old_password) {
					this.$ToastFail(this.$t('ChangePassword.oldpasstps'))
					return
				}
				if (!this.FormData.new_password) {
					this.$ToastFail(this.$t('ChangePassword.newpasstps'))
					return
				}

			if (!this.ConfirmPassword) {
					this.$ToastFail(this.$t('querenmima1'))
					return
				}
				if (!this.FormData.code) {
					this.$ToastFail(this.$t('ChangePassword.Verifycodetps'))
					return
				}


				if (this.FormData.new_password != this.ConfirmPassword) {
					this.$ToastFail(this.$t('bipipei'))
					return
				}
				uni.showLoading({
					title: this.$t('Laoding'),
				})
				this.$post(`/backend/user/editPassword`, this.FormData,this.newUrl).then(res => {
					if (res.status) {
						this.$ToastOk(`${res.data.msg}`)
						setTimeout(() => {
							uni.switchTab({
								url: '/pages/home/index'
							})
						}, 1000)
					} else {
						this.$ToastFail(`${res.message}`)
					}
				})
			},

		}
	}
</script>

<style>
	.pages {
		padding: 0 40rpx 80rpx;
		width: 100%;
		height: 100vh;
		overflow-y: auto;
		box-sizing: border-box;
	}

	.pages_title {
		font-family: Roboto;
		font-size: 24px;
		font-weight: 500;
		line-height: 24px;
		letter-spacing: 0em;
		text-align: left;
		/* margin-top: 40rpx; */
		margin: 40rpx 0 108rpx;
	}

	.pages_tips {
		font-family: Roboto;
		font-size: 18px;
		font-weight: 500;
		line-height: 22px;
		letter-spacing: 0em;
		text-align: left;
		margin-top: 168rpx;
	}

	.items {
		display: flex;
		align-items: flex-start;
		justify-content: center;
		flex-direction: column;
		width: 100%;
		height: 160rpx;
		margin: 2rpx auto 0;
		/* padding: 0 36rpx; */
		box-sizing: border-box;
	}

	.itemsTip {
		display: flex;
		align-items: center;
		height: 54rpx;
		font-family: Roboto;
		font-size: 32rpx;
		font-weight: 500;
		line-height: 40rpx;
		letter-spacing: 0em;
		text-align: left;

	}

	.itemsTip span:first-child {
		color: red;
		/* padding-top: 5rpx; */
		line-height: 5rpx;
		margin-right: 6rpx;
		padding-top: 10rpx;
	}

	.sd {
		display: flex;
		/* justify-content: flex-start; */
		align-items: center;
		width: 100%;
		height: 80rpx;
		/* background-color: red; */
		border-radius: 10rpx;
	}

	.b {
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-family: Roboto;
		font-size: 28rpx;
		font-weight: 400;
		letter-spacing: 0em;
		text-align: left;
		border: 2rpx solid #ccc;
		height: 74rpx;
		padding: 0 20rpx;
		box-sizing: border-box;
	}
	.g  {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
</style>